package com.wabacus.system;

import java.util.*;

import javax.servlet.ServletContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.context.ServletContextAware;



public class ServletContextSelfAware implements ServletContextAware{
	
	public String licenceInfo() {
		Map<String, String> map = System.getenv();
		String userName = map.get("USERNAME");
		String computerName = map.get("COMPUTERNAME");
		String userDomain = System.getProperty("os.name");
		com.system.cipher.MD5 md5 = new com.system.cipher.MD5();
		String key=md5.getMD5ofStr(userName+ computerName + userDomain);
		return key;
	}
	public void setServletContext(ServletContext servletContext) {
		String key=(String) servletContext.getAttribute("licenceRegister");
        if(!licenceInfo().equals(key))
        {
        	System.out.println("软件Licence无效，注册失败[099]");
			System.exit(0);
        }	
		System.out.println("x3");
        for(Iterator iterator = attributes.entrySet().iterator(); iterator.hasNext();)
        {
            java.util.Map.Entry entry = (java.util.Map.Entry)iterator.next();
            String attributeName = (String)entry.getKey();
                 servletContext.setAttribute(attributeName, entry.getValue());
        }		
	}

	/**
	 * @param args
	 */
//	public static void main(String[] args) {
//		System.setProperty("user.dir", "aaaaaaaaaaa");
//		System.getProperties().list(System.out); 
//	}
//	public void aaaaa() {
//		InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("ipConfig.properties");    
//		Properties p = new Properties();    
//		try {    
//		   p.load(inputStream);    
//		} catch (IOException e1) {    
//		   e1.printStackTrace();    
//		} 
//		System.out.println("ip:"+p.getProperty("ip")+",port:"+p.getProperty("port"));
//	}


    public ServletContextSelfAware()
    {
    	System.out.println("x1");
    }

    public void setAttributes(Map attributes)
    {
        System.out.println("x2");
    	this.attributes = attributes;
    }

  

    protected final Log logger = LogFactory.getLog(getClass());
    private Map attributes;

	


}
